<?php
	echo "<h2 id='contentTitle'>".$pageTitle."</h2>";
	echo $this->renderElement('message');

	if ($othAuth->hasPermission('formularios/add/')) {
		$addButton = "<span class=\"buttonAdd\">Cadastrar formulário</span>";
		echo html_entity_decode($html->link($addButton, '/formularios/add/',array('class'=>'button')));
	}
	
	if (isset($formularios) && is_array($formularios) && (!empty($formularios))) {
		echo "<br />";
		echo "<table>";
		/* Cabeçalho */
		echo "<thead>";
		echo "<div></div>";
		echo "<tr class='tableHeader'>";
		echo "<th class='tableHeaderBegin'>Nome</th>";
		$group = $othAuth->getData('group');
		$level =$group['level'];
		if ($level < 100) {
			echo "<th class='tableHeaderMiddle'>Entidade</th>";
		} 

		if ($othAuth->hasPermission('formularios/edit/')) {
			echo "<th class='tableHeaderMiddle'>Editar</th>";
		}
		if ($othAuth->hasPermission('formularios/delete/')) {
			echo "<th class='tableHeaderEnd'>Excluir</th>";
		}
		echo "</tr>";
		echo "</thead>";
		
		/* Rodapé */
		echo "<tfoot>";
		echo "<tr class='tableFooter'>
		<td colspan='100%'></td>
		</tr>";
		echo "</tfoot>";
		
		/* Registros */
		$i=0;
		foreach ($formularios as $formulario) {
			if (($i++ % 2) == 1) $zebrado = " class='oddTr' ";
			else $zebrado = "";
			echo "<tr ".$zebrado.">";
			echo "<td>".$html->link($formulario['Formulario']['name'],'/formularios/view/'.$formulario['Formulario']['id'])."</td>";
			if ($level < 100) {
				echo "<td>".$html->link($formulario['Organization']['nome'],'/organizations/view/'.$formulario['Organization']['id'])."</td>";
			}
			echo "<td class='tdCenter'>".html_entity_decode($html->link($html->image('fileedit.png',array('class'=>'icon')), '/formularios/edit/'.$formulario['Formulario']['id']))."</td>";
			echo "<td class='tdCenter'>".html_entity_decode($html->link($html->image('filedel.png',array('class'=>'icon')), '/formularios/delete/'.$formulario['Formulario']['id'], array(), 'Confirma a exclusão deste item?'))."</td>";
			echo "</tr>";
		}
		echo "</table>";
	} else {
		echo "<p>Não há formulário cadastrado.</p>";
	}
	
